package com.hyk.commonLib.common.utils.rx.activityResult;

import android.content.Intent;

import androidx.activity.result.ActivityResult;

import com.hyk.commonLib.common.activity.BaseActivity;

import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.core.SingleOnSubscribe;

class RxActivityResultInActivity extends RxActivityResult<BaseActivity<?>> {
    protected RxActivityResultInActivity(BaseActivity<?> activity) {
        super(activity);
    }

    @Override
    public Single<ActivityResultCompat> start(Intent intent) {
        return Single.create((SingleOnSubscribe<ActivityResult>) emitter -> container.startActivityLauncher.launch(intent, emitter::onSuccess))
                .map(ActivityResultCompat::convertFromActivityResult);
    }
}
